v = input()
l = 0
if len(v) == 4:
    for i in range(0,4):
        for h in range(i+1,5):
            g = int(v[i:h])
            f = 0
            for x in range (1, k + 1):
                if g % x == 0:
                    f = f + 1
            if f == 2:
                l == max(l,g)
print(l)